part of 'alert.dart';

///修改通道名称
class AlertChangeName extends StatelessWidget {
  final void Function(String input)? onPressed;
  final String name;
  AlertChangeName({Key? key, this.onPressed, required this.name})
      : super(key: key);

  final textEditingController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    textEditingController.zftext = name;
    return UnconstrainedBox(
        child: Material(
      color: Colors.transparent,
      child: Container(
        decoration: kAlertBoxDecoration,
        clipBehavior: Clip.hardEdge,
        height: 164,
        width: 312,
        padding: EdgeInsets.all(15),
        child: DefaultTextStyle(
          style: TextStyle(
            color: Colors.white,
          ),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            // crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Text(
                'Change Name to:',
                style: TextStyle(
                    color: Colors.white, fontSize: kAlertTitleFontSize),
              ),
              Row(
                children: [
                  Padding(
                    padding: const EdgeInsets.only(right: 8),
                    child: Text('Name:'),
                  ),
                  Expanded(
                      child: kAlertInput(controller: textEditingController)),
                ],
              ),
              Text(
                'Maximun 6 Characters',
                style: TextStyle(color: Colors.white.withOpacity(0.5)),
              ),
              Padding(
                padding: const EdgeInsets.only(top: 10),
                child: GestureDetector(
                  onTap: () {
                    var text = textEditingController.text;
                    if (text.isEmpty) {
                      Fluttertoast.showToast(msg: 'name cannot be empty');
                      return;
                    }
                    if (text.length > 6) {
                      text = text.substring(0, 6);
                    }
                    onPressed?.call(text);
                  },
                  child: Container(
                    decoration: borderDecoration(),
                    alignment: Alignment.center,
                    height: 30,
                    width: 80,
                    child: Text(
                      'OK',
                      style: TextStyle(color: Colors.white),
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    ));
  }
}
